package cn.xmy.demo01.servlet;

import cn.xmy.demo01.pojo.Trolley;
import cn.xmy.demo01.service.TrolleyDaoService;
import cn.xmy.demo01.service.impl.TrolleyDaoImplService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;


import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/commonCarServlet")
public class CommonCarServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        TrolleyDaoService trolleyDaoService = new TrolleyDaoImplService();
        List<Trolley> trolleys=null;
        try {
            trolleys=trolleyDaoService.findAllTrolley();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        request.setAttribute("carNumber",trolleys.size());
        request.getRequestDispatcher("head.html").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}